package com.comba.javafxdemo.utils;

import java.time.LocalDate;

public abstract class DateTimeUtils {
	private DateTimeUtils() {}

	public static String formatDate(LocalDate date) {
		if(date==null) {
			return "";
		}
		return date.getYear() + "/" + date.getMonthValue() + "/" + date.getDayOfMonth();
	}

	public static LocalDate parseDate(String value) {
		String[] splits = value.split("/");
		return LocalDate.of(Integer.parseInt(splits[0]), Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
	}

	public static boolean isValidDate(String value) {
		try {
			parseDate(value);
			return true;
		} catch(Exception e) {
			return false;
		}
	}
}
